package com.scoy.honeymei.adapter;

import android.content.Context;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.RatingBar;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.scoy.honeymei.adapter.tabadapter.OyAdapter;
import com.scoy.honeymei.bean.GoodsOrderBean;
import com.scoy.honeymei.bean.ShopBean;
import com.scoy.honeymei.databinding.ItemGoodsEvaBinding;
import com.scoy.honeymei.databinding.ItemShopnewListBinding;
import com.scoy.honeymei.utils.GlideImgUtil;

import org.jetbrains.annotations.NotNull;

public class EvaAdapter extends OyAdapter<GoodsOrderBean> {


    public EvaAdapter(Context context) {
        super(context);
    }

    @NonNull
    @NotNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        ItemGoodsEvaBinding binding = ItemGoodsEvaBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
        return new OyHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull RecyclerView.ViewHolder holder, int position) {
        OyHolder mHolder = (OyHolder) holder;
        GoodsOrderBean mBean = datalist.get(position);
        GlideImgUtil.glidePic(context, mBean.getImage(), mHolder.binding.iclIv);
        mHolder.binding.iclNameTv.setText(mBean.getName());
        mHolder.binding.iclPriceTv.setText("¥ "+mBean.getMoney());
        mHolder.binding.ratingBar.setRating(mBean.getStarTemp());

        mHolder.binding.ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
            @Override
            public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
                int mNum = (int) rating;
                mBean.setStarTemp(mNum);
            }
        });

        mHolder.itemView.setOnClickListener(v -> {
            if (onOneClick != null) {
                onOneClick.oneClick(position);
            }
        });

    }

    static class OyHolder extends RecyclerView.ViewHolder {
        private ItemGoodsEvaBinding binding;

        public OyHolder(ItemGoodsEvaBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }

}
